package com.yunxi.controller.eai;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.baseDataToHub.pojo.iam.PmsPostVO;
import com.yunxi.baseDataToHub.pojo.iam.PmsUserVO;
import com.yunxi.baseDataToHub.service.iam.IamDubboService;
import com.yunxi.core.util.DESUtil;
import com.yunxi.core.web.ApiResult;
import com.yunxi.eai.pojo.esb.EsbVO;
import com.yunxi.eai.service.iam.IamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/5/15.
 */
@RestController
@RequestMapping("/esb/api")
@Api(tags = "esb:manage", description = "接收esb信息")
public class IAMController {

 /*   @Reference(version = "${demo.service.version}",
            application = "${dubbo.application.id}",
            registry = "${dubbo.registry.address}",
            // url = "${dubbo.application.url}",
            check = false,
            timeout = 10000
    )*/
    @Autowired
    private IamService iamService;
    @Autowired
    private IamDubboService iamDubboServiceImpl;

    @PostMapping("/findData")
    @ApiOperation(value = "获取初始数据")
    public Object findData(EsbVO esbVO) throws Exception {

        Object object=iamService.findData(esbVO);
        return object;
    }

    @PostMapping("/findIamData")
    @ApiOperation(value = "获取IAM数据")
    public Object findData(String serviceName, String beginTime, String endTime) throws Exception {

        ApiResult apiResult = iamDubboServiceImpl.findDataByConditional(serviceName, beginTime, endTime);

        return apiResult;
    }
    @PostMapping("/findUpsUserData")
    @ApiOperation(value = "获取UPS人员数据")
    public Object findUpsUserByConditional(String serviceName,String iamSystem, String beginTime, String endTime) throws Exception {

        ApiResult apiResult = iamDubboServiceImpl.findUpsUserByConditional(serviceName,iamSystem, beginTime, endTime);

        return apiResult;
    }



    @PostMapping("/sendPmsPost")
    @ApiOperation(value = "发送渠道岗位信息")
    public Object sendPmsPost(@RequestBody List<PmsPostVO> pmsPostVO) throws Exception {

        ApiResult apiResult = iamDubboServiceImpl.sendPmsPost(pmsPostVO);

        return apiResult;
    }

    @PostMapping("/sendUserData")
    @ApiOperation(value = "发送用户数据")
    public Object sendUserData(@RequestBody PmsUserVO pmsUserVO) throws Exception {
        //pmsUserVO.setPassword(DESUtil.encrypt(pmsUserVO.getPassword()));
        List list=new ArrayList();
        list.add(pmsUserVO);
        ApiResult apiResult = iamDubboServiceImpl.sendIamUserVO(list);

        return apiResult;
    }
}

